<script setup>
import {ref,watch} from 'vue';
let text= ref("")
let isRed=ref(false)
watch(()=>text.value,(newValue,oldValue)=>{
    console.log("oldValue",oldValue)
    console.log("newValue",newValue)

    console.log("newValue".includes("我"))
    if(newValue.includes("我")){
        isRed.value=true
        // let newtext=newValue.substring(0,newValue.length-1);
        // console.log(newtext)
        // text.value=newtext
        // alert("勿作死");
    }
})
</script>

<template>
<div>
    <input type="text" placeholder="请输入，不能有‘我’" v-model="text" class="bg_yellow" :class="{bg_red:isRed}"></input>
</div>

</template>

<style scoped>
.bg_yellow{
    background-color: yellow;
}
.bg_red{
    background-color: red;
}
</style>